package top.hidoctor.auscultation.net.p;

import android.content.Context;

import com.tang.base.BaseResponse;
import com.tang.base.NetMapEncryptUtils;
import com.tang.base.PatchRequest;
import com.tang.net.SuccessConsumer;

import java.util.Map;

import io.reactivex.functions.Consumer;
import top.hidoctor.auscultation.bean.UserBean;
import top.hidoctor.auscultation.bean.YangbenBean;
import top.hidoctor.auscultation.net.PresenterWrapper;
import top.hidoctor.auscultation.net.c.SendPackageContract;
import top.hidoctor.auscultation.net.req.UserReq;
import top.hidoctor.auscultation.net.req.AuditZdReq;
import top.hidoctor.auscultation.net.req.LabelZdReq;
import top.hidoctor.auscultation.net.req.SimleReq;

public class SendPackagePresenter extends PresenterWrapper<SendPackageContract.View> implements SendPackageContract.Presenter {
    public SendPackagePresenter(Context context, SendPackageContract.View view) {
        super(context, view);
    }


    @Override
    public void getYbList(final SimleReq req) {
        mView.showLoading();
        add(mService.getSample(new NetMapEncryptUtils(req).getMaps())
                .compose(this.<String>getTransformer())
                .subscribe(new SuccessConsumer<BaseResponse<String>>(mView, mContext) {
                    @Override
                    public void onSuccess(BaseResponse<String> response) {
                        mView.hideLoading();
                        mView.getYbListSuc(response.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                }));
    }

    @Override
    public void getUserList(final UserReq req) {
        mView.showLoading();
        add(mService.getUser(new NetMapEncryptUtils(req).getMaps())
                .compose(this.<UserBean>getTransformer())
                .subscribe(new SuccessConsumer<BaseResponse<UserBean>>(mView, mContext) {
                    @Override
                    public void onSuccess(BaseResponse<UserBean> response) {
                        mView.hideLoading();
                        mView.getUserListSuc(response.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                }));
    }

    @Override
    public void addLabel(LabelZdReq req) {
        mView.showLoading();
        final Map<String, Object> maps = new NetMapEncryptUtils(req).getMaps();
        PatchRequest patchRequest = new PatchRequest(maps);
        add(mService.addLabelZd(patchRequest.getRequestBody())
                .compose(this.getTransformer())
                .subscribe(new SuccessConsumer<BaseResponse<Object>>(mView, mContext) {
                    @Override
                    public void onSuccess(BaseResponse<Object> response) {
                        mView.hideLoading();
                        mView.addLabelSuc();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                }));
    }

    @Override
    public void addAudit(AuditZdReq req) {
        mView.showLoading();
        final Map<String, Object> maps = new NetMapEncryptUtils(req).getMaps();
        PatchRequest patchRequest = new PatchRequest(maps);
        add(mService.addAuditZd(patchRequest.getRequestBody())
                .compose(this.getTransformer())
                .subscribe(new SuccessConsumer<BaseResponse<Object>>(mView, mContext) {
                    @Override
                    public void onSuccess(BaseResponse<Object> response) {
                        mView.hideLoading();
                        mView.addAuditSuc();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                }));
    }

    @Override
    public void getDifficult() {
        mView.showLoading();
        add(mService.getDifficult(new NetMapEncryptUtils("").getMaps())
                .compose(this.<YangbenBean>getTransformer())
                .subscribe(new SuccessConsumer<BaseResponse<YangbenBean>>(mView, mContext) {
                    @Override
                    public void onSuccess(BaseResponse<YangbenBean> response) {
                        mView.hideLoading();
                        mView.getDifficultSuc(response.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                }));
    }


}
